﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Data.SqlClient;


/// <summary>
/// Summary description for DataAcess
/// </summary>
public class DataService
{
    String chuoiketnoi = ConfigurationManager.ConnectionStrings["QLBH"].ConnectionString;
    SqlConnection _connect;
    public DataService()
	{
		
	}
    public DataTable LayDuLieu(string sql, params SqlParameter[] thamso)
    {
        moketnoi();
        DataTable bangdulieu = new DataTable();
        SqlCommand command = new SqlCommand(sql,_connect);
        command.Parameters.AddRange(thamso);
        bangdulieu.Load(command.ExecuteReader());
        dongketnoi();
        return bangdulieu;

    }
    public void Capnhatdulieu(string sql, params SqlParameter[] thamso)
    {
        moketnoi();
       
        SqlCommand command = new SqlCommand(sql, _connect);
        command.Parameters.AddRange(thamso);
        command.ExecuteNonQuery();
       
        dongketnoi();
        

    }
 
    
    void moketnoi()
    {
        _connect = new SqlConnection(chuoiketnoi);
        _connect.Open();
    }
    void dongketnoi()
    {

        _connect.Close();
    }
}